package xiegd.study.eval;


import org.junit.Test;
import org.junit.platform.commons.util.StringUtils;
//import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.util.regex.Pattern;

/**
 * @Author: xieguangda
 * @Description:
 * @Date: 2023/4/11 17:52
 */
public class MyTest1 {
    private static Pattern pattern = Pattern.compile("[0-9]*");

    public static void main(String[] args) {
        //BigDecimal bigDecimal = test333("12+(1131-110)/20");
        BigDecimal bigDecimal = test333("11+(110.3-3)/30");
        System.out.println("我是结果啊：：：" + bigDecimal);
    }

    @Test
    public void mytet333(){
        BigDecimal bigDecimal = test333("11+(110.3-3)/30");
        System.out.println("我是结果啊：：：" + bigDecimal);
    }

    private static BigDecimal test333(String s) {
        //判断是否为常量
        if(isNumeric(s)){
            return new BigDecimal(s);
        }
        String[] splitAdd = s.split("\\+");
        BigDecimal sumBig = new BigDecimal(0);
        if(splitAdd == null){
            return sumBig;
        }
        String s12 = splitAdd[0];
        String sAddAll = splitAdd[1];
        if(StringUtils.isBlank(s12)){
           // sumBig.add(new BigDecimal(s1));
            return sumBig;
        }
        if(StringUtils.isBlank(sAddAll)){
            return sumBig;
        }

        String[] splitC = sAddAll.split("/");
        if(splitC == null){
            return sumBig;
        }
        String sCAll = splitC[0];
        String s20 = splitC[1];

        if(sCAll == null){
            return sumBig;
        }

        String[] splitJ = sCAll.split("-");
        if(splitJ == null){
            return sumBig;
        }
        String s110 = splitJ[1];
        s110 = s110.replaceAll("[^0-9\\\\.]","");

        String s111 = splitJ[0];
        s111 = s111.replaceAll("[^0-9\\\\.]","");

        if(StringUtils.isNotBlank(s20) && StringUtils.isNotBlank(s110) && StringUtils.isNotBlank(s111)){
            BigDecimal sumBig2 = new BigDecimal(s111).subtract(new BigDecimal(s110)).divide(new BigDecimal(s20),BigDecimal.ROUND_CEILING).add(new BigDecimal(s12));
            return sumBig2;
        }
        return sumBig;
    }

    public static boolean isNumeric(String str){
        return pattern.matcher(str).matches();
    }
}
